<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <div th:include="common/head_info::head_infor"></div>
    <title>新增客户</title>
</head>
<body>
<div class="container center">
    <h2>新增路线</h2>
    <form role="form" id="myForm">
        <div class="form-group">
            <label for="associatorName">昵称</label>
            <input type="text" class="form-control" id="associatorName" placeholder="请输入昵称">
        </div>
        <div class="form-group">
            <label for="phone">手机号</label>
            <input type="text" class="form-control" id="phone" placeholder="请输入手机号">
        </div>

        <div class="form-group">
            <label for="emergencyTel">紧急联系人电话</label>
            <input type="text" class="form-control" id="emergencyTel" placeholder="请输入紧急联系人电话">
        </div>
        <div class="form-group">
            <label for="realName">真是姓名</label>
            <input type="text" class="form-control" id="realName" placeholder="请输入真实姓名">
        </div>
        <div class="form-group">
            <label for="identity">身份证号</label>
            <input type="text" class="form-control" id="identity" placeholder="请输入身份证号">
        </div>
        <div class="form-group">
            <label for="email">邮箱</label>
            <input type="text" class="form-control" id="email" placeholder="请输入邮箱">
        </div>
        <div class="form-group">
            <label for="sex">性别</label>
            <select class="form-control " id="sex">
                <option value="0">男</option>
                <option value="1">女</option>
            </select>
        </div>
        <div class="form-group">
            <label for="file">头像</label>
            <input type="file" id="file">
        </div>
        <div class="form-group">
            <label for="province">省份</label>
            <input type="text" class="form-control" id="province" placeholder="请输入省份">
        </div>
        <div class="form-group">
            <label for="city">城市</label>
            <input type="text" class="form-control" id="city" placeholder="请输入城市">
        </div>
        <div class="form-group">
            <label for="address">详细地址</label>
            <input type="text" class="form-control" id="address" placeholder="请输入详细地址">
        </div>
        <button type="button" id="submit" class="btn btn-default">提交</button>
    </form>
</div>
<script>
    //带文件
    function getFormData() {
        var formData = new FormData();
        formData.append("associatorName", $('#associatorName').val());
        formData.append("phone", $('#phone').val());
        formData.append("province", $('#province').val());
        formData.append("address", $('#address').val());
        formData.append("realName", $('#realName').val());
        formData.append("sex", $('#sex').val());
        formData.append("identity", $('#identity').val());
        formData.append("email", $('#email').val());
        formData.append("emergencyTel", $('#emergencyTel').val());
        formData.append("file", $('#file')[0].files[0]);
        return formData;
    }

    $('#submit').click(function () {
        var formData = getFormData();
        $.ajax({
            url: "/associator/addByDetail",
            type: "post",
            dataType: "json",
            data: formData,
            processData: false,
            contentType: false,
            success: function (json) {
                $("#myForm")[0].reset();
                alert("新增成功");
            }, error: function () {
                alert("新增失败")
            }
        })
    })
</script>
</body>
</html>